import { Socket } from "dgram";
import WebSocket from "ws";
/**创建 WebSocket 服务器指定 8800 端口**/
const server: WebSocket.WebSocketServer = new WebSocket.WebSocketServer({ port: 8800 })
/**建立连接后给 Socket 添加事件监听**/
server.on("connection", (socket: Socket) => {
  /**收到消息后触发 onMessage 事件，将收到的信息进行处理后转发给客户端**/
  socket.on('message', (data: Buffer) => {
    const res: string = data.toString()
    const message: string = res.replace("吗", "").replace("？", "！")
    socket.send(message)        //转发消息
  });
})

import Koa2 from 'koa2'
const app = new Koa2();
const main = (ctx) => {
  const {request,response} = ctx;
  ctx.response.body = `Hello World`;
  console.log({request});
  console.log({response});
};
app.use(main);
app.listen(3000);

